package com.why.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.why.entity.Examlist;
import com.why.service.ExamlistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * (Examlist)表控制层
 *
 * @author makejava
 * @since 2023-05-27 23:48:52
 */
@RestController
@RequestMapping("/examlist")
@CrossOrigin
public class ExamlistController {
    /**
     * 服务对象
     */
    @Autowired
    private ExamlistService examlistService;

    @PostMapping("/save")
    public String save(@RequestBody Examlist examlist) {

        if (examlist.getStudentid() == null) {
            return "no";
        } else {
            LambdaQueryWrapper<Examlist> queryWrappe = new LambdaQueryWrapper<Examlist>();
            queryWrappe.eq(Examlist::getExaminationid, examlist.getExaminationid()).eq(Examlist::getStudentid, examlist.getStudentid());
            Examlist one = examlistService.getOne(queryWrappe);
            if (one == null) {
                examlistService.save(examlist);
                return "success";
            } else {
                return "exist";
            }
        }
    }


    @PostMapping("/update")
    public String update(@RequestBody Examlist examlist) {
        LambdaQueryWrapper<Examlist> queryWrapper = new LambdaQueryWrapper<Examlist>();
        queryWrapper.eq(Examlist::getExaminationid, examlist.getExaminationid());
        queryWrapper.eq(Examlist::getStudentid, examlist.getStudentid());
        Examlist one = examlistService.getOne(queryWrapper);
        if (one == null) {
            return "no";
        } else {
            examlistService.update(examlist, queryWrapper);
            return "success";
        }
    }

}

